package time;

import java.time.LocalDateTime;

/**
 * 日期时间相关测试
 */
public class LocalDateTimeTest {
    public static void main(String[] args) {
        now();
        customDateTime();
        alterDateTime();
    }

    private static void alterDateTime() {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime plusYears = now.plusYears(2);
        LocalDateTime minusYears = now.minusYears(2);
        LocalDateTime dateTime = now.withYear(2012);
        System.out.println("now = " + now);
        System.out.println("dateTime = " + dateTime);
        System.out.println("plusYears = " + plusYears);
        System.out.println("minusYears = " + minusYears);
    }

    private static void customDateTime() {
        LocalDateTime dateTime = LocalDateTime.of(2020, 2, 2, 15, 12, 12);
        System.out.println("dateTime = " + dateTime);
    }

    private static void now() {
        LocalDateTime now = LocalDateTime.now();
        System.out.println("now = " + now);
    }
}
